<template>
  <div class="index">
    <div class="formBox">
        <p class="item"><span class="name">礼物名称 ：</span><input v-model="date.name" class="slong" placeholder="请输入内容"></input></p>
        <p class="item"><span class="name">礼物图片 ：</span>
            <img class="t2" :src="date.image">
            <a href="javascript:;" class="file">选择文件<input type="file" @change="upImg" id="imgTest" class="mel" accept=".gif,.jpg,.jpeg,.png"></a>
        </p>
        <p class="item"><span class="name">礼物价格 ：</span>
            <input v-model="date.price" value="" class="solt" placeholder="请输入内容"></input>
        </p>
        <p class="item"><span class="name">排序值 ：</span>
            <input type="number" v-model="date.sort" value="" class="solt" placeholder="请输入内容"></input>
        </p>

<!--         <p class="item"><span class="name">是否上架 ：</span>
    <select v-model="date.is_sale">
      <option value="1">上架</option>
      <option value="2">下架</option>
    </select>
</p> -->
        <p class="item inputBox">
          <button @click="submit" class="submitInput">确定</button>
          <button @click="empty" class="emptyInput">重置</button>
        </p>
    </div>
    
  </div>
</template>
<script>
import Vue from 'vue'
import axios from 'axios'
import { Get, Post ,Put ,Delete} from '@/config/api'

export default {
  name: 'index',
  data() {
    return {
        list:[],
        listId:'',
        last:1,//顶级分类
        date:{
          store_id:0,
          name:'',
          price:'',
          image:'',
          sort:''
        }
    }
  },
  mounted(){

  },
  watch:{
  },
  computed:{
    //检查表单
    VueFrom(){
      if(this.Input(this.date.goods_name)&&this.Input(this.date.goods_logo)&&this.Input(this.date.goods_price)&&this.Input(this.date.goods_number)){
        return true
      }else{
        return false
      }
    }
  },

  methods: {
    async submit() {
      this.$store.dispatch("loadOpen");
      let that=this
      let data={
          "store_id":this.date.store_id,
          "name":this.date.name,
          "price":this.date.price,
          "image":this.date.image,
          "sort":this.date.sort
      }
      await Post('/gift',this.$store.state.token,data).then((reg)=>{
        console.log(reg)
        this.$router.push('/prcList')
      })
      this.$store.dispatch("loadClose");
    },
    //清空信息
    empty() {
      for(var key in this.date){
        this.date[key]=''
      }
    },
    //图片上传
    upImg(e){
      let file = e.target.files[0]; //input 
      if( file.size > 0.3*1024*1024 ){  //用size属性判断文件大小不能超过200k
        alert( "你上传的文件太大了！" ) 
      }else{
        let that=this
        let reader = new FileReader(); 
        reader.readAsDataURL(file); 
        reader.onload = function(e){ 
          var res = this.result; 
          that.date.image=this.result 
        } 
      } 
    }

  }
}

</script>
